package ass.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ass.beans.CinemaBean;
import ass.beans.UserBean;
import ass.dao.support.CinemaDAOImpl;
import ass.dao.support.UserDAOImpl;

/**
 * Servlet implementation class AddCinemaServlet
 */
public class AddCinemaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String location = (String) request.getParameter("location");
		String seat = (String)request.getParameter("seat");
		String atm = (String) request.getParameter("atm");
		String widescreen = (String) request.getParameter("widescreen");
		String snack = (String) request.getParameter("snack");
		String restaurant = (String) request.getParameter("restaurant");

		CinemaBean cinemabean = new CinemaBean();
		cinemabean.setCinema_location(location);
		cinemabean.setCinema_seating_capacity(seat);
		cinemabean.setHas_atm(atm);
		cinemabean.setHas_widescreen(widescreen);
		cinemabean.setHas_snack_bar(snack);
		cinemabean.setHas_restaurant(restaurant);

		CinemaDAOImpl cinemaDAOImpl = new CinemaDAOImpl();
		cinemaDAOImpl.insert(cinemabean);

		response.setContentType("text/html");// from response, set content type
		PrintWriter out = response.getWriter();// from response, get output
												// writer
		out.write("Cinema insert succesful");
		//out.close();
		
		String nextJSP = "";
		nextJSP = "/ownerAddCinema.jsp";
		request.setAttribute("cinema_inserted",  "<font color='green'>Cinema inserted</font>");
		
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
		dispatcher.forward(request, response);
		
//		 }else {
//		 // String nextJSP = "/register.jsp";
//		 // RequestDispatcher dispatcher =
//		 getServletContext().getRequestDispatcher(nextJSP);
//		 // dispatcher.forward(request,response);
//		 response.setContentType("text/html");// from response, set content
//		 type
//		 PrintWriter out = response.getWriter();// from response, get output
//		 writer
//		 out.write("aaaa" + username);
//		 out.close();
//		 }

	}

}
